import { ajax } from '@/utils'

import type {
  BlockItem,
  GetGroupListRes,
  GetVideoDetailRes,
  GetVideoLimitRes,
  GetVideoListRes,
  IndexPicRes,
  NewGoods
} from './materialTypes'

const baseUrl = '/yswy-zy-source-material-manage'

const baseUrl2 = '/yswy-zy-activity'

export default {
  /** 获取视频列表 */
  getVideoList(data): Promise<GetVideoListRes> {
    return ajax.post(`${baseUrl}/video/list`, data)
  },
  /** 新建视频 */
  createVideo(data) {
    return ajax.post(`${baseUrl}/video/create`, data)
  },
  /** 批量删除视频 */
  batchDeleteVideo(data) {
    return ajax.delete(`${baseUrl}/video/batchDel`, { data })
  },
  /** 获取视频详情 */
  getVideoDetail(id: number): Promise<GetVideoDetailRes> {
    return ajax.get(`${baseUrl}/video/detail/${id}`)
  },
  /** 更新视频 */
  updateVideo(data) {
    return ajax.put(`${baseUrl}/video/edit`, data)
  },
  /** 批量移动视频分组 */
  batchMoveVideoGroup(data) {
    return ajax.put(`${baseUrl}/video/moveGroup`, data)
  },
  /** 获取分组列表 */
  getGroupList(): Promise<GetGroupListRes> {
    return ajax.get(`${baseUrl}/videoGroup/list`)
  },
  /** 新建分组 */
  createGroup(data) {
    return ajax.post(`${baseUrl}/videoGroup/add`, data)
  },
  /** 重命名分组 */
  renameGroup(data) {
    return ajax.put(`${baseUrl}/videoGroup/rename`, data)
  },
  /** 删除分组 */
  deleteGroup(id: number) {
    return ajax.delete(`${baseUrl}/videoGroup/del/${id}`)
  },
  /** 获取视频数量上限 */
  getVideoLimit(): Promise<GetVideoLimitRes> {
    return ajax.get(`${baseUrl}/video/limit`)
  },
  /** 获取首页图 */
  getIndexPic(): Promise<IndexPicRes> {
    return ajax.get(`${baseUrl2}/index/detail`)
  },
  /** 编辑首页图 */
  editIndexPic(data: IndexPicRes) {
    return ajax.put(`${baseUrl2}/index/edit`, data)
  },
  /**获取金刚区列表 */
  getBlockList(): Promise<BlockItem[]> {
    return ajax.post(`${baseUrl2}/diamondArea/Config/selectDiamondAreaConfig`)
  },
  /**编辑金刚区*/
  editBlockItem(data: BlockItem): Promise<any> {
    return ajax.post(`${baseUrl2}/diamondArea/Config/edit`, data)
  },
  /**禁用/启用金刚区*/
  forbidBlockItem(id: number, status: 0 | 1): Promise<any> {
    return ajax.post(`${baseUrl2}/diamondArea/Config/switch`, { id, status })
  },
  /**获取上新商品*/
  getNewGoods(): Promise<NewGoods> {
    return ajax.post(`${baseUrl2}/goodsNewRule/detail`)
  },

  /**编辑上新商品*/
  editNewGoods(
    newProductDeadline: number,
    newGoodsIds: number[]
  ): Promise<any> {
    return ajax.post(`${baseUrl2}/goodsNewRule/edit`, {
      newProductDeadline,
      newGoodsIds
    })
  },

  /**上新推送*/
  sendNewGoodsMsg(data): Promise<any> {
    return ajax.post(`${baseUrl2}/pointGoods/newProductsPushToWx`, data)
  }
}
